﻿/**
*	Pants3D
*	@author 	Liam O'Donnell 2007-12-18
**/

package com.spikything.pants3d {

	import com.spikything.pants3d.*;
	import com.spikything.pants3d.core.*;
	import com.spikything.pants3d.events.*;
	import com.spikything.pants3d.objects.*;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.filters.BlurFilter;
	import flash.geom.ColorTransform;
	import flash.ui.Keyboard;
	import flash.utils.getTimer;

	public class Pants3D {

		public static const NORMAL 	:String 	= "Sprite3D"; 	// xy plane (default)
		public static const WALL 	:String 	= "WallPlane"; 	// yx plane
		public static const FLOOR 	:String 	= "FloorPlane"; // zx plane
		public var host 			:Sprite; 					// Where we will add the canvas
		public var canvas 			:Canvas; 					// Where we add and render our sprites
		public var projector 		:Projector; 				// Renders the sprites and view
		
		public function Pants3D (host:Sprite, canvasWidth:int, canvasHeight:int, background:Number = -1) {
			this.host = host;
			canvas = new Canvas(canvasWidth, canvasHeight, background);
			host.addChild(canvas);
			projector = new Projector(canvas);
			disable();
		}
		
		public function get sprites ():Array { return projector.sprites };
		
		public function get autoUpdateSprites ():Boolean { return projector.autoUpdateSprites };
		public function set autoUpdateSprites (value:Boolean):void { projector.autoUpdateSprites = value };
		
		public function kill ():void {
			disable();
			projector.kill();
			projector = null;
			trace("projector: "+projector);
			while (canvas.numChildren) canvas.removeChildAt(0);
			host.removeChild(canvas);
			canvas = null;
		}
		
		public function update (e:Event = null):void { projector.update() };
		public function startLoop ():void { projector.startLoop() };
		public function stopLoop ():void { projector.stopLoop() };
		public function renderTestGrid ():void { projector.renderTestGrid() };
		public function addRandomSprites (what:Class, number:int, spread:Number):void { projector.addRandomSprites(what, number, spread) };
		public function setCamProps (viewDist:Number, maxDist:Number, fadeFactor:Number, minAlpha:Number, minDist:Number, damping:Number=9, friction:Number=.6, mouseSwayX:Number = 0, mouseSwayY:Number = 0):void { projector.setCamProps(viewDist, maxDist, fadeFactor, minAlpha, minDist, damping, friction, mouseSwayX, mouseSwayY) };
		public function setCamMotion (x:Number, y:Number, z:Number, vrx:Number = 0, vry:Number = 0, vrz:Number = 0):void { projector.setCamMotion(x, y, z, vrx, vry, vrz) };
		public function setCamTarget (what:IRenderable):void { projector.setCamTarget(what) };
		public function get camTargetOffset ():Point3D { return projector.camTargetOffset };
		public function set camTargetOffset (what:Point3D):void { projector.camTargetOffset = what };
		public function get keysEnabled ():Boolean { return projector.keysEnabled };
		public function set keysEnabled (value:Boolean):void { projector.keysEnabled = value };
		public function setCamPos (x:Number, y:Number, z:Number):void { projector.setCamPos(x, y, z) };
		public function setCamRotation (rx:Number, ry:Number, rz:Number):void { projector.setCamRotation(rx, ry, rz) };
		public function setDepthQueueColours (r:Number, g:Number, b:Number, factor:Number = 1, maxLuminosity:Number = 1):void { projector.setDepthQueueColours(r, g, b, factor, maxLuminosity) };
		public function enable ():void { projector.enable() };
		public function disable ():void { projector.disable() };
		public function toggleMouse ():void { projector.mouseControlled = projector.ready = !projector.mouseControlled };
		public function addSprite (child:Sprite = null, x:Number = 0, y:Number = 0, z:Number = 0, myClass:Class = null, wrap:Boolean = false):Sprite3D { return projector.addSprite(child, x, y, z, myClass, wrap) };
		public function removeSprite (which:IRenderable):void { projector.removeSprite(which) };
		//public function setPhysicsProps (damp:Number = 9, friction:Number = .6, gravity:Number = 3, elastic:Number = .3):void { projector.setPhysicsProps(damp, friction, gravity, elastic) };

	}
	
}